package com.example.demo.controller;

import ch.qos.logback.core.util.StringUtil;
import jakarta.servlet.http.HttpSession;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {
    @RequestMapping("/login")
    public Boolean login(String username, String password, HttpSession session) {
//        if(username==null||password==null||"".equals(username)||"".equals(password)){
//            return false;
//        }
        //校验参数合法性
        if (!StringUtils.hasLength(username) || !StringUtils.hasLength(password)) {
            return false;
        }
        if (username.equals("admin") && password.equals("123456")) {
            session.setAttribute("username", "admin");
            return true;
        }
        return false;
    }
    @RequestMapping("/getUserInfo")
    public String getUserInfo(HttpSession session){
        String username = (String) session.getAttribute("username");
        return username;
    }
}
